package com.meiyou.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.meiyou.pojo.JuBao;
import com.meiyou.service.JubaoService;
import com.meiyou.utils.Msg;
import com.meiyou.utils.PagesMap;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@Api(value = "举报接口", tags = { "举报接口" })
@RequestMapping("/jubao")
public class JuBaoController {

	@Autowired
	JubaoService jubaoService;
	
		//插入举报信息
		@RequestMapping(value="/insertJuBao",method = RequestMethod.POST)
		@ResponseBody
		@ApiOperation(value="插入举报信息")
		public Msg showAll(String z_u_count,String z_jbcontext,String z_u_bcount,String zType){
		   
			JuBao jubao = new JuBao();
			jubao.setZ_jbcontext(z_jbcontext);
			jubao.setZ_state("未审核");
			Date date = new Date();
			jubao.setZ_time(date);
			jubao.setZ_u_bcount(z_u_bcount);
			jubao.setZ_u_count(z_u_count);
			jubao.setzType(zType); 
			jubaoService.insertJubao(jubao);
			return Msg.success();
		}
		
		//审核举报信息
		@RequestMapping(value="/updateJubao",method = RequestMethod.POST)
		@ResponseBody
		@ApiOperation(value="审核举报信息")
		public Msg updateJubao(int id,String z_state){
			JuBao jubao = new JuBao();
			jubao.setZ_id(id);
			jubao.setZ_state(z_state); 
			jubaoService.updateJubao(jubao);
			return Msg.success();
		}
		
		//展示所有举报信息
		@RequestMapping(value="/selectAllJuBao",method = RequestMethod.POST)
		@ResponseBody
		@ApiOperation(value="显示举报信息")
		public Msg showAll(int pn,JuBao jubao){
			String strtime = jubao.getStrtime();
			if(strtime!=null && strtime!="") {
				String s[] = strtime.split(",");
			    jubao.setStarttime(s[0]);
			    jubao.setEndtime(s[1]); 
			}			
			System.out.println(jubao);
			List<JuBao> list = jubaoService.selectJubaoAll(jubao);
			Map<String,Object> map = PagesMap.getpagesJubaoMaps(list, pn);
			return Msg.success().add("pageInfo", map);			
	    }
		
		//删除举报信息
		@RequestMapping(value="/deletejubao",method = RequestMethod.POST)
		@ResponseBody
		@ApiOperation(value="删除举报信息")
		public Msg deletejubao(int id){
			jubaoService.deleteJubao(id);
			return Msg.success();
		}
		
		//根据id获取举报信息
		@RequestMapping(value="/selectById",method = RequestMethod.POST)
		@ResponseBody
		@ApiOperation(value="查询信息通过Id")
		public Msg selectById(int id){
			JuBao jubao = jubaoService.selectById(id);
			return Msg.success().add("jubao", jubao); 
		}		
}
